{template 'pc_header'}
<link rel="stylesheet" type="text/css" href="{MODULE_URL}template/mobile/app/css/screen_lottery_nfree6.css">
<script src="{MODULE_URL}template/mobile/app/js/lotter_free_base.js" type="text/javascript" charset="utf-8"></script>
<script src="{MODULE_URL}template/mobile/app/js/screen_lottery_nfree.js" type="text/javascript" charset="utf-8"></script>
<!---->
<script src="{MODULE_URL}template/mobile/app/js/MyTool-nfree6.js" type="text/javascript" type="text/javascript"></script>  
</head>
<body class="FUN LOTTERY_FREE" {if !empty($basic_config['bg_vedio'])}data-vide-bg="{php echo tomedia($basic_config['bg_vedio'])}"{/if}>
<audio id="Audio_Running" src="" loop preload="preload"></audio>
<audio id="Audio_Result" src="" preload="preload"></audio>
{template 'top_panel'}
<div class="Panel Lottery"  >
<div class="table-box">
            <div class="table">
              
                <img class="seat-img2" src="{MODULE_URL}template/mobile/app/images/xysjh/seat-img2.png">
                <img class="seat-img3" src="{MODULE_URL}template/mobile/app/images/xysjh/seat-img3.png">
                 <img class="seat-img4" src="{MODULE_URL}template/mobile/app/images/xysjh/seat-img4.png">
                <img class="seat-img1" src="{MODULE_URL}template/mobile/app/images/xysjh/seat-img3.png">
               
                <span class="table-num" id="jqDeskText" >0</span>
                <div id="jqAddDeskAni" class="table-move">
                    <span  id="jqDeskText1" class="table-move1">0</span>
                </div>
                <div class="table-button">
                <div class="table-btn display0" style=" display:none">
                <p>最大号数：</p><input type="text" value="1"     id="zhmax" >
                </div>
                    <div class="table-btn">
                        <p>抽奖数量：</p>
                        <select id="sltAwardNum" >
                            <option value="请选择" selected="selected" style="display: none;">请选择</option>
                            
                            <option value="1">
                                1</option>
                            
                            <option value="2">
                                2</option>
                            
                            <option value="3">
                                3</option>
                            
                            <option value="4">
                                4</option>
                            
                            <option value="5">
                                5</option>
                            
                            <option value="6">
                                6</option>
                            
                            <option value="7">
                                7</option>
                            
                            <option value="8">
                                8</option>
                            
                            <option value="9">
                                9</option>
                            
                            <option value="10">
                                10</option>
                            
                        </select>
                    </div>
                    <button id="jqStart" onclick="Start();">开始抽奖</button>
                    <button id="jqEnd" class="hide" onclick="End();">停止抽奖</button>
                    <div class="clear"></div>
                </div>
            </div>
            <div class="table-win">
                    <ul class="table-list" id="jqResultBox" >
                </ul>
            </div>
        </div> 
</div>
 <script type="text/javascript">
        var t2='{php echo json_encode($mobiles)}';
		var myobj=eval(t2);
		var zam_data = [];
        var timerObj = null;
        var awardData = [];
        var numberData = [];
        var deskNum =myobj.length;
		$("#zhmax").val(deskNum);
		setzhmaxarr();
		function setzhmaxarr(){
				   deskNum = parseInt($("#zhmax").val());
					for (var i = 0; i <  deskNum; i++) {
						numberData[i] = myobj[i].mobile;
						zam_data[i] = myobj[i].mobile;
					}
		}
        
        function Start() {
			if(timerObj!=null){
				clearInterval(timerObj);
			}
			deskNum = parseInt($("#zhmax").val());
			setzhmaxarr();
            $("#jqResultBox").html("");
            var awardNum = parseInt($("#sltAwardNum").val()) || 0;

            

            if (deskNum <= 0) {
                MyTool.Alert("录入手机号的用户为0、无法抽取");
                return;
            }
			if(awardNum > deskNum){
				MyTool.Alert('目前手机号码仅仅有'+deskNum+'个、请重新选择抽取个数');
                return;
			}
            if (awardNum <= 0) {
                MyTool.Alert("请选择抽奖数量");
                return;
            }
            $("#jqStart").attr("disabled", true);
            RandomDesk();
            GetAwardDesk(deskNum, awardNum);
        }
        function RandomDesk() {
            timerObj = setInterval(function () {
                var index = Math.floor(Math.random() * zam_data.length);
                var n = zam_data[index];
                $("#jqDeskText").text(n);
            }, 300);
        }
        function GetAwardDesk(deskNum, awardNum) {
            awardData = [];            
            for (var i = 0; i < awardNum&&deskNum>0; i++) {
                var index = Math.floor(Math.random() * numberData.length);
                awardData[i] = numberData[index];
                numberData.splice(index,1);

            }
            $("#jqStart").addClass("hide");
            $("#jqEnd").removeAttr("disabled").removeClass("hide");
        }
        function End() {
            $("#jqAddDeskAni").removeClass("table-moving");
            var i = 0;
            var func = function () {
                clearInterval(timerObj);
                ShowResult(awardData[i]);
                i++;
                if (awardData.length > i) {
                    setTimeout(function () {
                        RandomDesk();
                    }, 500); //间隔
                    setTimeout(function () {
                        func();
                    }, 1000);
					
                } else {
                    $("#jqEnd").addClass("hide");
                    $("#jqStart").removeAttr("disabled").removeClass("hide");
                }
            };
			
            if (awardData.length > 0) {
                $("#jqEnd").attr("disabled", true);
                func();
            } else {
                clearInterval(timerObj);
                MyTool.Alert("号码已经抽完！", function () {
                    $("#jqDeskText,#jqDeskText1").text(0);
                    $("#jqEnd").addClass("hide");
                    $("#jqStart").removeAttr("disabled").removeClass("hide");
                });
            }
        }
        function ShowResult(num) {
            $("#jqAddDeskAni").addClass("table-moving");
            $("#jqDeskText,#jqDeskText1").text(num);
            var liHtml = '<li>' + num + '</li>';
            setTimeout(function () {
                $("#jqAddDeskAni").removeClass("table-moving");
                $("#jqResultBox").prepend(liHtml);
            }, 900);
        }
    </script>
{template 'pc_footer'}